public class Checker {
      public boolean checkBST(TreeNode root) {
		  return dfs(root, Integer.MIN_VALUE, Integer.MAX_VALUE);
	    }

	private boolean dfs(TreeNode root, int minValue, int maxValue) {
		if(root == null) {
			return true;
		}
		int t = root.val;
		if(t <= minValue || t >= maxValue) {
			return false;
		}
		return dfs(root.left,minValue,root.val) && dfs(root.right, root.val, maxValue);
		
	}
}

public class Checker {
    
    boolean checkBST(TreeNode root) {
        // write code here
       int num[] = new int [10000];
       int cnt = 0;
         Stack<TreeNode> sta = new Stack<>();
        while(!sta.empty() || root != null)
        {
            if(root !=null)
            {
                sta.push(root);
                root = root.left;
            }
            else
            {
                root = sta.pop();
                num[cnt ++] = root.val;
                root = root.right;
            }
        }
        for(int i = 1;i < cnt;i ++){
            if(num[i] > num[i -1]) continue;
            else return false;
        }
        return true;
    }
}
